package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Live;
import com.ruoyi.system.service.ILiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 直播用户管理Controller
 * @date 2022-11-08
 */
@RestController
@RequestMapping("/system/live")
public class LiveController extends BaseController
{
    @Autowired
    private ILiveService liveService;

    /**
     * 查询直播用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:live:list')")
    @GetMapping("/list")
    public TableDataInfo list(Live live)
    {
        startPage();
        List<Live> list = liveService.selectLiveList(live);
        return getDataTable(list);
    }

    /**
     * 导出直播用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:live:export')")
    @Log(title = "直播用户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Live live)
    {
        List<Live> list = liveService.selectLiveList(live);
        ExcelUtil<Live> util = new ExcelUtil<Live>(Live.class);
        util.exportExcel(response, list, "直播用户管理数据");
    }
    /**
     * 获取直播用户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:live:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {return AjaxResult.success(liveService.selectLiveById(id));}
    /**
     * 新增直播用户管理
     */
    @PreAuthorize("@ss.hasPermi('system:live:add')")
    @Log(title = "直播用户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Live live)
    {return toAjax(liveService.insertLive(live));}
    /**
     * 修改直播用户管理
     */
    @PreAuthorize("@ss.hasPermi('system:live:edit')")
    @Log(title = "直播用户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Live live)
    {return toAjax(liveService.updateLive(live));}
    /**
     * 删除直播用户管理
     */
    @PreAuthorize("@ss.hasPermi('system:live:remove')")
    @Log(title = "直播用户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {return toAjax(liveService.deleteLiveByIds(ids));}
}
